package com.tesis_2.UI;

import java.io.UnsupportedEncodingException;
import java.text.ParseException;
import java.util.ArrayList;

import com.example.tesis_2.R;
import com.example.tesis_2.R.layout;
import com.example.tesis_2.R.menu;
import com.tesis_2.BL.BLReservas;
import com.tesis_2.BL.BLSeguridad;
import com.tesis_2.MO.MOComentario;
import com.tesis_2.MO.MOLocal;
import com.tesis_2.MO.MOReserva;
import com.tesis_2.Utils.UTComentariosArrayAdapter;
import com.tesis_2.Utils.UTReservasArrayAdapter;

import android.os.Bundle;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.ListView;

public class UIMisReservas extends ListActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		//setContentView(R.layout.activity_uimis_reservas);
		ArrayList<MOReserva> lsReservas = new ArrayList<MOReserva>();
		try {
			lsReservas = BLReservas.getReservasByUserId(BLSeguridad.getObjUusario().getId());
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		setListAdapter( new UTReservasArrayAdapter(this, lsReservas));
		
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_uimis_reservas, menu);
		return true;
	}
	
	@Override 
    public void onListItemClick(ListView l, View v, int position, long id) {
		
		MOReserva res = (MOReserva) getListAdapter().getItem(position);
		
		if (res.getStatus()==2)
		{
			Intent intent = new Intent(getApplicationContext(), UIComentar.class);
			intent.putExtra("resid", res.getId());
			startActivity(intent);
		}
		
		
		
    }

}
